/**
 * 
 */
package com.nari.basic.service;

import com.nari.basic.dao.IRoleDao;
import com.nari.basic.dao.IRoleMenuDao;
import com.nari.basic.dao.IUserDao;
import com.nari.basic.dao.IUserRoleDao;
import com.nari.basic.model.IRole;
import com.nari.basic.model.IUser;
import com.nari.platform.model.ResponseMsg;
import com.nari.resconfig.dao.IProjectResourceConfigDao;

/**
 * 基础信息的级联维护
 * @author Xiaopeng
 * @date 2014-5-13
 */
public class BasicResourceCascadeMgrServiceImpl implements IBasicResourceCascadeMgrService {
	private IUserDao iUserDao;
	private IUserRoleDao iUserRoleDao;
	private IProjectResourceConfigDao iProjectResourceConfigDao;
	private IRoleDao iRoleDao;
	private IRoleMenuDao iRoleMenuDao;
	
	/**
	 * 通过用户唯一标识删除与之关联的所有信息
	 * @param userUID
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-5-13
	 */
	public ResponseMsg deleteUserCascadeByUserUID(String userUID) throws Exception {
		IUser user = null;
		if(userUID!=null && !"".equals(userUID)) {
			user = iUserDao.queryEntityById(userUID);
		}
		/* 删除用户的关联信息 */
		this.iUserRoleDao.deleteByUserUID(userUID); //用户角色
		//用户访问控制列表
		this.iProjectResourceConfigDao.deleteProjResAuthorityByUserInfo(userUID);
		if(user == null) {
			return ResponseMsg.getInstance(false, "User information don't exist，operatation can't excute!");
		}
		//用户信息
		this.iUserDao.deleteEntityById(userUID);
		return ResponseMsg.getInstance(true, "");
	}
	
	/**
	 * 通过角色唯一标识删除与之关联的所有信息
	 * @param roleUID
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-5-13
	 */
	public ResponseMsg deleteRoleCascadeByRoleUID(String roleUID) throws Exception {
		IRole role = null;
		if(roleUID!=null && !"".equals(roleUID)) {
			role = iRoleDao.queryEntityById(roleUID);
		}
		/* 删除角色的关联信息 */
		this.iRoleMenuDao.deleteByRoleUID(roleUID); //角色菜单信息
		//角色用户信息
		this.iUserRoleDao.deleteByRoleUID(roleUID);
		if(role == null) {
			return ResponseMsg.getInstance(false, "User Information don't exists,operatation can't excute!");
		}
		//角色信息
		this.iRoleDao.deleteEntityById(roleUID);
		return ResponseMsg.getInstance(true, "");
	}
	
	/**
	 * @return the iUserDao
	 */
	public IUserDao getiUserDao() {
		return iUserDao;
	}

	/**
	 * @param iUserDao the iUserDao to set
	 */
	public void setiUserDao(IUserDao iUserDao) {
		this.iUserDao = iUserDao;
	}

	/**
	 * @return the iUserRoleDao
	 */
	public IUserRoleDao getiUserRoleDao() {
		return iUserRoleDao;
	}

	/**
	 * @param iUserRoleDao the iUserRoleDao to set
	 */
	public void setiUserRoleDao(IUserRoleDao iUserRoleDao) {
		this.iUserRoleDao = iUserRoleDao;
	}

	/**
	 * @return the iProjectResourceConfigDao
	 */
	public IProjectResourceConfigDao getiProjectResourceConfigDao() {
		return iProjectResourceConfigDao;
	}

	/**
	 * @param iProjectResourceConfigDao the iProjectResourceConfigDao to set
	 */
	public void setiProjectResourceConfigDao(
			IProjectResourceConfigDao iProjectResourceConfigDao) {
		this.iProjectResourceConfigDao = iProjectResourceConfigDao;
	}

	/**
	 * @return the iRoleDao
	 */
	public IRoleDao getiRoleDao() {
		return iRoleDao;
	}

	/**
	 * @param iRoleDao the iRoleDao to set
	 */
	public void setiRoleDao(IRoleDao iRoleDao) {
		this.iRoleDao = iRoleDao;
	}

	/**
	 * @return the iRoleMenuDao
	 */
	public IRoleMenuDao getiRoleMenuDao() {
		return iRoleMenuDao;
	}

	/**
	 * @param iRoleMenuDao the iRoleMenuDao to set
	 */
	public void setiRoleMenuDao(IRoleMenuDao iRoleMenuDao) {
		this.iRoleMenuDao = iRoleMenuDao;
	}
	
}
